package com.wb;

import com.wb.Dao.BookDao;
import com.wb.Factory.BookDaoFactory;
import com.wb.Factory.BookDaoInstanceFactory;
import com.wb.Service.BookService;
import com.wb.Service.impl.BookServiceImpl;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Main {
    public static void main(String[] args) {
        /**
         *  静态工厂造对象
         */
//        BookDao bookDao = BookDaoFactory.getBookDao();
//        bookDao.save();
        AbstractApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        applicationContext.registerShutdownHook();
        BookDao bookDao = (BookDao) applicationContext.getBean("bookDao");
        bookDao.save();
//        applicationContext.close(); // close方法比较暴力
//        applicationContext.
//        BookService bookService1 = (BookService) applicationContext.getBean("service1");
//        BookService bookService2 = (BookService) applicationContext.getBean("service1");

//        bookService.save();
//        System.out.println(bookService1);
//        System.out.println(bookService2);

//        BookDaoInstanceFactory bookDaoInstanceFactory = new BookDaoInstanceFactory();
//        BookDao bookDao = bookDaoInstanceFactory.getBookDao();
//        bookDao.save();

//        为什么Bean默认为单例
//        如果不是单例，则对象会非常多
//        Springg构造对象时调用的是无参构造函数
    }
}
